#ifndef MyThreadPool_h__
#define MyThreadPool_h__

#include <pthread.h>
#include <vector>
#include <queue>


typedef void*(*ThreadProc)(void* data);

const int DEAULT_THREAD_NUMBER = 4;
const int DEAULT_QUEUE_NUMBER = 1024;



namespace myrpc
{
	namespace mythread
	{
		class MyThreadPool
		{
		public:
			MyThreadPool();
			~MyThreadPool();
			int Add(ThreadProc func, void* data);
		
			void Start();
			enum THREADSTAT
			{
				WAITING,
				RUNNING,
				FINISHED
			};
		
		
			struct Thread
			{
				THREADSTAT stat;
				int id;
				pthread_t pid;
			};
		
			struct WorkNode
			{
				ThreadProc threadproc;
				void* data;
			};
		private:
			static void* Threadfuction(void* data);
			std::vector<Thread*> _vecThread;
			static pthread_mutex_t _queuelock;
			static std::queue<WorkNode*> _workqueue;
			static int fd[2];
			size_t _threadnumb;
			size_t _queuemaxsize;
		};
	}
}

#endif // MyThreadPool_h__
